package com.siriframe.mq;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(topic = "test",
        consumerGroup = "test-group",
        selectorExpression = "*")
public class Consumer implements RocketMQListener<MessageExt> {

//    @Override
//    public void onMessage(String message) {
//        log.info("Receive message：" + message);
//
//        //如果消费失败，则抛出RuntimeException，RocketMQ会自动重试
//        throw new RuntimeException("消费失败");
//    }

//    @Override
//    public void onMessage(Message message) {
//        log.info("Receive message: {}",message.getBody());
//
//        //如果消费失败，则抛出RuntimeException，RocketMQ会自动重试
//        throw new RuntimeException("消费失败");
//    }

    @Override
    public void onMessage(MessageExt message) {
        log.info("Receive messageId：{} message: {}",message.getMsgId(),new String(message.getBody()));

        //如果消费失败，则抛出RuntimeException，RocketMQ会自动重试
        throw new RuntimeException("消费失败");
    }
}
